//
//  MainTabBar.swift
//  SinaWeiboDemo
//
//  Created by 伍禄林 on 16/9/20.
//  Copyright © 2016年 伍禄林. All rights reserved.
//

import UIKit

class MainTabBar: UITabBar {

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUi()
    }
    
    required init?(coder aDecoder: NSCoder) {
        //fatalError("init(coder:) has not been implemented")
        super.init(coder: aDecoder)
        setupUi()
    }
    
    private func setupUi() {
        
        addSubview(compseBtn)
        
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        let w = self.bounds.width / 5
        let h = self.bounds.height
        
        var index: CGFloat = 0;
        
        for subview in subviews {
            
            if(subview.isKind(of: NSClassFromString("UITabBarButton")!)){
                
                subview.frame = CGRect(x: w * index, y: 0, width: w, height: h)
                
                if index == 1{
                    index = 2
                }
                
                index += 1
                
            }
            
        }
//        能过让compseBtn向上凸起
//        compseBtn.frame = CGRect(x: w * 2, y: -20, width: w, height: h)
//        
//        bringSubview(toFront: self)
        
        compseBtn.frame = CGRect(x: w * 2, y: 0, width: w, height: h)

    }
    
    lazy var compseBtn: UIButton = {
    
        let btn = UIButton();
        
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button"), for: UIControlState.normal)
        
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), for: UIControlState.highlighted)
        
        btn.setImage(UIImage(named: "tabbar_compose_icon_add"), for: UIControlState.normal)
        
        btn.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), for: UIControlState.highlighted)
        
        btn.sizeToFit()

        
        return btn
    
    }()

}
